﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DadaBase.Data;
using MySql.Data.MySqlClient;
namespace LoginSystem
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(MainWindow_Loaded);

        }

        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            //连接到数据库
            DBConnection.Active = DBConnection.Open("127.0.0.1", "test", "root", "daiguanzhong");

            //如果连接失败，提示并退出
            if (DBConnection.Active == null)
            {
                MessageBox.Show("服务器数据库连接失败，程序即将退出！");
            }
            else
            {
                MessageBox.Show("服务器数据库连接成功！");
            }
//            SELECT * FROM test.user_table LIMIT 0, 1000	3 row(s) returned
              

            //string sql = string.Format("SELECT * FROM test.user_table WHERE name = rock");
            //using (MySqlDataReader rdr = DBConnection.Active.Reader(sql))
            //{
            //    rdr.Read();
            //    string pwd = (string)rdr["pwd"];
            //    int i = 1;

            //}
            //DBConnection.Active.Execute("insert into Agent values('11','11','11','22','22','22','22')");
            DBConnection.Active.Execute("INSERT INTO `test`.`user_table` (`name`, `pwd`, `ch_name`, `age`) VALUES ('mao', '0', '12', 12)");

            //INSERT INTO `test`.`user_table` (`name`, `pwd`, `ch_name`, `age`) VALUES ('mao', '0', '12', 12)
            string sql = "SELECT ch_name FROM test.user_table WHERE name = @name";
            string id = (string)DBConnection.Active.Scalar(sql, DBConnection.MakeParameter("@name", MySqlDbType.VarChar, "rock"));
            if (id == null)
            {

            }


        }
    }
}
